import Clipboard from 'clipboard'
import { toastSuccess, toastError } from './toast'

export default function handleClipboard(text, event) {
  const clipboard = new Clipboard(event.target, {
    text: () => {
      return text
    },
  })
  clipboard.on('success', () => {
    toastSuccess('拷贝成功！')
    clipboard.destroy()
  })
  clipboard.on('error', () => {
    toastError('拷贝失败！')
    clipboard.destroy()
  })
  clipboard.onClick(event)
}
